﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Model;
using BLL;

public partial class Admin_WeiMenuEdit : BasePage
{
    Access access = new Access();
    WeiMenuBO wbo = new WeiMenuBO();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (GetQeuryString("para") == "update")
            {
                InitData();
            }
            else if (GetQeuryString("para") == "add")
            {
                
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (GetQeuryString("para") == "update")
        {
            WeiMenu menu = GetEntity();
            menu.ID = Convert.ToInt32(GetQeuryString("id"));
            wbo.Update(menu);
            AlertAndCloseAndReloadParend("保存成功！", "test");
        }
        else if (GetQeuryString("para") == "add")
        {
            WeiMenu menu = GetEntity();
            wbo.Add(menu); ;
            AlertAndCloseAndReloadParend("保存成功！", "test");
        }
    }

    private void InitData()
    {
        string id = GetQeuryString("id");
        DataSet ds = access.GetWeiMenuEntityById(id);
        DataRow dr = ds.Tables[0].Rows[0];
        this.txtMenuName.Text = dr["Name"].ToString();
        this.txtKey.Text = dr["keys"].ToString();
        this.txtSequnce.Text = dr["suqence"].ToString();
        DropDownList1.SelectedValue = dr["type"].ToString();
    }

    public WeiMenu GetEntity()
    {
        WeiMenu menu = new WeiMenu();
        menu.Name = this.txtMenuName.Text;
        menu.Key = this.txtKey.Text;
        menu.Suqence = this.txtSequnce.Text;
        menu.ParentID = Convert.ToInt32(GetQeuryString("ParentId"));
        menu.MID = CurrentUserInfo.MID;
        menu.Type = DropDownList1.SelectedValue;
        return menu;
    }
}